package com.koron.css2.clientCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.mapper.ConfigMapper;
import com.koron.css2.baseConfig.queryBean.ConfigQueryBean;
import com.koron.css2.baseConfig.vo.ConfigVO;
import com.koron.css2.clientCenter.mapper.UserInfoMapper;
import com.koron.css2.clientCenter.queryBean.UserInfoQueryBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

public class ClearYearWater implements ServerInterface {
    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            //year_water
            UserInfoQueryBean userInfoBean = JsonUtils.objectToPojo(req.getData(), UserInfoQueryBean.class);
            UserInfoMapper userInfoMapper = factory.getMapper(UserInfoMapper.class);
            ConfigMapper mapper = factory.getMapper(ConfigMapper.class);
            ConfigQueryBean bean = new ConfigQueryBean();
            bean.setConfigName("transfer_clear_water");
            List<ConfigVO> list = mapper.selectConfigList(bean);
            if (list != null && list.size()>0){
                ConfigVO configVO = list.get(0);
                if ("是".equals(configVO.getConfigValue())){
                    userInfoMapper.clearYearWater(userInfoBean.getUserNo());
                }
            }
            return MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", void.class);
        }catch (Exception e) {
            logger.error("年用水量清空失败", e);
            return MessageBean.create(Constant.MESSAGE_INT_FAIL, "年用水量清空失败", void.class);
        }
    }
}
